package acwing._2LanQiao._13No13;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._13No13
 * @File : Q4653.java
 * @Author : WangRuoyu
 * @Date : 2023/3/31 9:16
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Q4653 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        words = br.readLine().split(" ");
        int m = Integer.parseInt(words[0]);
        int[][] nums = new int[n][2];
        for (int i = 0; i < n; ++i) {
            nums[i][1] = i + 1;
            int x = i + 1;
            int ans = 0;
            while (x > 0) {
                ans += x % 10;
                x /= 10;
            }
            nums[i][0] = ans;
        }
        Arrays.sort(nums, (o1, o2) -> o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1]);
        System.out.println(nums[m - 1][1]);
    }
}

